package com.ruoyi.point.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.point.pojo.AlarmLog;
import com.ruoyi.point.service.IAlarmLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报警日志记录Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/system/log")
public class AlarmLogController extends BaseController
{
    @Autowired
    private IAlarmLogService alarmLogService;

    /**
     * 查询报警日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlarmLog alarmLog)
    {
        startPage();
        List<AlarmLog> list = alarmLogService.selectAlarmLogList(alarmLog);
        return getDataTable(list);
    }

    /**
     * 导出报警日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "报警日志记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlarmLog alarmLog)
    {
        List<AlarmLog> list = alarmLogService.selectAlarmLogList(alarmLog);
        ExcelUtil<AlarmLog> util = new ExcelUtil<AlarmLog>(AlarmLog.class);
        util.exportExcel(response, list, "报警日志记录数据");
    }

    /**
     * 获取报警日志记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{alarmLogId}")
    public AjaxResult getInfo(@PathVariable("alarmLogId") Long alarmLogId)
    {
        return success(alarmLogService.selectAlarmLogByAlarmLogId(alarmLogId));
    }

    /**
     * 新增报警日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "报警日志记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlarmLog alarmLog)
    {
        return toAjax(alarmLogService.insertAlarmLog(alarmLog));
    }

    /**
     * 修改报警日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "报警日志记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlarmLog alarmLog)
    {
        return toAjax(alarmLogService.updateAlarmLog(alarmLog));
    }

    /**
     * 删除报警日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "报警日志记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alarmLogIds}")
    public AjaxResult remove(@PathVariable Long[] alarmLogIds)
    {
        return toAjax(alarmLogService.deleteAlarmLogByAlarmLogIds(alarmLogIds));
    }
}
